<?php

namespace app\admin\model\user;

use think\Model;


class Deposit extends Model
{

    

    

    // 表名
    protected $name = 'user_deposit';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'ispay_text',
        'authen_tui_text',
        'authen_time_text',
        'add_time_text',
        'pay_time_text',
        'type_text'
    ];
    

    
    public function getIspayList()
    {
        return ['1' => __('Ispay 1'), '0' => __('Ispay 0')];
    }

    public function getAuthenTuiList()
    {
        return ['1' => __('Authen_tui 1'), '2' => __('Authen_tui 2'), '3' => __('Authen_tui 3')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }


    public function getIspayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ispay']) ? $data['ispay'] : '');
        $list = $this->getIspayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthenTuiTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authen_tui']) ? $data['authen_tui'] : '');
        $list = $this->getAuthenTuiList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthenTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authen_time']) ? $data['authen_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getAddTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setAuthenTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setAddTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'user_id', [], 'LEFT')->setEagerlyType(0);
    }
}
